package com.youyou.fusheng2.View.WelcomPage;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.youyou.fusheng2.FuShengMain;
import com.youyou.fusheng2.Moudle.FuShengCallBack;
import com.youyou.fusheng2.Person.FuShengMoudle;
import com.youyou.fusheng2.R;
import com.youyou.fusheng2.Utils.WindowTouMing;

import java.util.Timer;
import java.util.TimerTask;

public class threeTimePage extends AppCompatActivity implements FuShengCallBack {

    private ImageView viewpageIma;
    private TextView viewpageTv;
    private TextView tv;
    private MyHander myHander = new MyHander();
    private FuShengMoudle fuShengMoudle = new FuShengMoudle(this);
    private Timer timer = new Timer();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        new WindowTouMing(this).windoe();
        setContentView(R.layout.three_time_page);
        initView();
        getHttp();
        start();
    }

    private void start() {
        /**
         *  @作者: $浮生-qq:2567294605$
         *  @时间: 2020/9/8  14:10
         *  @简介: 跳转到其他页面
         */
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                Message message = new Message();
                message.what = 1;
                message.obj = "okok";
                myHander.sendMessage(message);
            }
        };
        timer.schedule(timerTask, 3000);
    }

    private void getHttp() {
        /**
         *  @作者: $浮生-qq:2567294605$
         *  @时间: 2020/9/8  13:53
         *  @简介: 获取每日必应一图
         */

    }

    private void initView() {
        viewpageTv = (TextView) findViewById(R.id.tv_day);
        tv = (TextView) findViewById(R.id.tv);

        startShakeByViewAnim(tv,1,1,1,1500);

//        tv.animate().rotation(360).setDuration(2000);
    }

    private void startShakeByViewAnim(View view, float scaleSmall, float scaleLarge, float shakeDegrees, long duration) {
        if (view == null) {
            return;
        }
        //由小变大
        Animation scaleAnim = new ScaleAnimation(scaleSmall, scaleLarge, scaleSmall, scaleLarge);
        //从左向右
        Animation rotateAnim = new RotateAnimation(-shakeDegrees, shakeDegrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

        scaleAnim.setDuration(duration);
        rotateAnim.setDuration(duration / 10);
        rotateAnim.setRepeatMode(Animation.REVERSE);
        rotateAnim.setRepeatCount(10);

        AnimationSet smallAnimationSet = new AnimationSet(false);
        smallAnimationSet.addAnimation(scaleAnim);
        smallAnimationSet.addAnimation(rotateAnim);

        view.startAnimation(smallAnimationSet);
    }


    @Override
    public void GetSuccess(String text, int mark) {
        Message message = new Message();
        message.what = mark;
        message.obj = text;
        myHander.sendMessage(message);
    }

    @Override
    public void GetError(String text, int mark) {
        Message message = new Message();
        message.what = mark;
        message.obj = text;
        myHander.sendMessage(message);
    }


    public class MyHander extends Handler {

        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0) {

            } else if (msg.what == 1) {
                startActivity(new Intent(threeTimePage.this, FuShengMain.class));
                finish();
            } else {
                Toast.makeText(threeTimePage.this, "Erro！！！！", Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        timer.cancel();
        myHander = null;
    }
}